package com.parser.apk;

/**
 * Created by admin on 2017/12/5.
 */
public class AndroidXML {
    public static final int CHUNK_HEADER_SIZE = 8;
    public static final int TABLE_HEADER_SIZE = CHUNK_HEADER_SIZE + 4;
    public static final int STRING_POOL_HEADER_SIZE = CHUNK_HEADER_SIZE + 20;
    public static final int RES_TREE_NODE_SIZE = CHUNK_HEADER_SIZE + 8;
    public static final int RES_TREE_NAMESPACE_EXT_SIZE = 8;
    public static final int RES_XML_TREE_ATTR_EXT_SIZE = 20;
    public static final int RES_XML_TREE_END_ELEMENT_EXT_SIZE = 8;
    public static final int STRING_POOL_REF_SIZE = 4;
    public static final int RES_XML_TREE_ATTRIBUTE_SIZE = 20;

    public static final int ATTR_BUFFER_SIZE = 128;

    public static final int RES_NULL_TYPE = 0x0000;
    public static final int RES_STRING_POOL_TYPE = 0x0001;
    public static final int RES_TABLE_TYPE = 0x0002;
    public static final int RES_XML_TYPE = 0x0003;

    // Chunk types in public static final int RES_XML_TYPE
    public static final int RES_XML_FIRST_CHUNK_TYPE = 0x0100;
    public static final int RES_XML_START_NAMESPACE_TYPE = 0x0100;
    public static final int RES_XML_END_NAMESPACE_TYPE = 0x0101;
    public static final int RES_XML_START_ELEMENT_TYPE = 0x0102;
    public static final int RES_XML_END_ELEMENT_TYPE = 0x0103;
    public static final int RES_XML_CDATA_TYPE = 0x0104;
    public static final int RES_XML_LAST_CHUNK_TYPE = 0x017f;
    // This contains a uint32_t array mapping strings in the string
    // pool back to public static final int RESource identifiers.  It is optional.
    public static final int RES_XML_RESOURCE_MAP_TYPE = 0x0180;

    // Chunk types in public static final int RES_TABLE_TYPE
    public static final int RES_TABLE_PACKAGE_TYPE = 0x0200;
    public static final int RES_TABLE_TYPE_TYPE = 0x0201;
    public static final int RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
    public static final int RES_TABLE_LIBRARY_TYPE = 0x0203;

    public static final int SORTED_FLAG = 1 << 0;
    public static final int UTF8_FLAG = 1 << 8;

    public static final int TYPE_NULL = 0x00;
    // The 'data' holds a ResTable_ref; a reference to another resource
    // table entry.
    public static final int TYPE_REFERENCE = 0x01;
    // The 'data' holds an attribute resource identifier.
    public static final int TYPE_ATTRIBUTE = 0x02;
    // The 'data' holds an index into the containing resource table's
    // global value string pool.
    public static final int TYPE_STRING = 0x03;
    // The 'data' holds a single-precision floating point number.
    public static final int TYPE_FLOAT = 0x04;
    // The 'data' holds a public static final int COMPLEX number encoding a dimension value;
    // such as "100in".
    public static final int TYPE_DIMENSION = 0x05;
    // The 'data' holds a public static final int COMPLEX number encoding a fraction of a
    // container.
    public static final int TYPE_FRACTION = 0x06;
    // The 'data' holds a dynamic ResTable_ref; which needs to be
    // resolved before it can be used like a public static final int TYPE_REFERENCE.
    public static final int TYPE_DYNAMIC_REFERENCE = 0x07;
    // The 'data' holds an attribute resource identifier; which needs to be resolved
    // before it can be used like a public static final int TYPE_ATTRIBUTE.
    public static final int TYPE_DYNAMIC_ATTRIBUTE = 0x08;

    // Beginning of integer flavors...
    public static final int TYPE_FIRST_INT = 0x10;

    // The 'data' is a raw integer value of the form n..n.
    public static final int TYPE_INT_DEC = 0x10;
    // The 'data' is a raw integer value of the form 0xn..n.
    public static final int TYPE_INT_HEX = 0x11;
    // The 'data' is either 0 or 1; for input "false" or "true" respectively.
    public static final int TYPE_INT_BOOLEAN = 0x12;

    // Beginning of color integer flavors...
    public static final int TYPE_FIRST_COLOR_INT = 0x1c;

    // The 'data' is a raw integer value of the form #aarrggbb.
    public static final int TYPE_INT_COLOR_ARGB8 = 0x1c;
    // The 'data' is a raw integer value of the form #rrggbb.
    public static final int TYPE_INT_COLOR_RGB8 = 0x1d;
    // The 'data' is a raw integer value of the form #argb.
    public static final int TYPE_INT_COLOR_ARGB4 = 0x1e;
    // The 'data' is a raw integer value of the form #rgb.
    public static final int TYPE_INT_COLOR_RGB4 = 0x1f;

    // ...end of integer flavors.
    public static final int TYPE_LAST_COLOR_INT = 0x1f;

    // ...end of integer flavors.
    public static final int TYPE_LAST_INT = 0x1f;

    public static final int COMPLEX_UNIT_SHIFT = 0;
    public static final int COMPLEX_UNIT_MASK = 0xf;

    // TYPE_DIMENSION: Value is raw pixels.
    public static final int COMPLEX_UNIT_PX = 0;
    // TYPE_DIMENSION: Value is Device Independent Pixels.
    public static final int COMPLEX_UNIT_DIP = 1;
    // TYPE_DIMENSION: Value is a Scaled device independent Pixels.
    public static final int COMPLEX_UNIT_SP = 2;
    // TYPE_DIMENSION: Value is in points.
    public static final int COMPLEX_UNIT_PT = 3;
    // TYPE_DIMENSION: Value is in inches.
    public static final int COMPLEX_UNIT_IN = 4;
    // TYPE_DIMENSION: Value is in millimeters.
    public static final int COMPLEX_UNIT_MM = 5;

    // TYPE_FRACTION: A basic fraction of the overall size.
    public static final int COMPLEX_UNIT_FRACTION = 0;
    // TYPE_FRACTION: A fraction of the parent size.
    public static final int COMPLEX_UNIT_FRACTION_PARENT = 1;

    // Where the radix information is; telling where the decimal place
    // appears in the mantissa.  This give us 4 possible fixed point
    // representations as defined below.
    public static final int COMPLEX_RADIX_SHIFT = 4;
    public static final int COMPLEX_RADIX_MASK = 0x3;

    // The mantissa is an integral number -- i.e.; 0xnnnnnn.0
    public static final int COMPLEX_RADIX_23p0 = 0;
    // The mantissa magnitude is 16 bits -- i.e; 0xnnnn.nn
    public static final int COMPLEX_RADIX_16p7 = 1;
    // The mantissa magnitude is 8 bits -- i.e; 0xnn.nnnn
    public static final int COMPLEX_RADIX_8p15 = 2;
    // The mantissa magnitude is 0 bits -- i.e; 0x0.nnnnnn
    public static final int COMPLEX_RADIX_0p23 = 3;

    // Where the actual value is.  This gives us 23 bits of
    // precision.  The top bit is the sign.
    public static final int COMPLEX_MANTISSA_SHIFT = 8;
    public static final int COMPLEX_MANTISSA_MASK = 0xffffff;

    public static final int DATA_NULL_UNDEFINED = 0;
    // The value is explicitly defined as empty.
    public static final int DATA_NULL_EMPTY = 1;

    public static class ResChunkHeader {
        public short type;
        public short headerSize;
        public int size;
    }

    public static class ResStringPoolHeader extends ResChunkHeader {
        public int stringCount;
        public int styleCount;
        public int flags;
        public int stringsStart;
        public int stylesStart;
    }

    public static class ResStringContent {
        public short size;
        public String content;
    }

    public static class ResStringPoolRef {
        public int index;
    }

    public static class ResStringPoolSpan extends ResStringPoolRef {
        public int firstChar;
        public int lastChar;
    }

    public static class ResXMLTreeHeader extends ResChunkHeader {

    }

    public static class ResXMLTreeNameSpaceExt {
        public ResStringPoolRef prefix;
        public ResStringPoolRef uri;
    }

    public static class ResXMLTreeNode extends ResChunkHeader {
        public int lineNumber;
        public ResStringPoolRef comment;
    }

    public static class ResXMLTreeCdataExt {
        public ResStringPoolRef ns;
        public ResStringPoolRef name;
    }

    public static class ResXMLTreeAttrExt extends ResXMLTreeCdataExt {
        public short attributeStart;
        public short attributeSize;
        public short attributeCount;
        public short idIndex;
        public short classIndex;
        public short styleIndex;
    }

    public static class ResXMLTreeAttribute extends ResXMLTreeCdataExt {
        public ResStringPoolRef rawValue;
        public ResValue typedValue;
    }

    public static class ResValue {
        public short size;
        public byte res0;
        public byte dataType;
        public int data;
    }

    public static class ResXMLTreeEndElementExt extends ResXMLTreeCdataExt {

    }

    public static class ResTableRef {
        public int ident;
    }

    public static class ResTableHeader extends ResChunkHeader {
        public int packageCount;
    }

    public static class ResTablePackage extends ResChunkHeader {
        public int id;
        public short[] name;
        public int typeStrings;
        public int lastPublicType;
        public int keyStrings;
        public int lastPublicKey;
    }
}
